var validator;

function validateLandDetails() {
    var pls_enter_reference_no = $("#pls_enter_reference_no").val();
    var pls_enter_name_of_the_land = $("#pls_enter_name_of_the_land").val();
    var pls_enter_valid_no = $("#pls_enter_valid_no").val();
    var pls_select_gn_division = $("#pls_select_gnDivision").val();
    var pls_enter_valid_lot_no = $("#pls_enter_valid_lot_no").val();

    var pls_enter_FileNo = $("#pls_enter_FileNo").val();
    var pls_select_District = $("#pls_select_District").val();
    var pls_select_RailwayTrack = $("#pls_select_RailwayTrack").val();
    var pls_select_DistrictEngineerZone = $("#pls_select_DistrictEngineerZone").val();
    var pls_select_IPWZone = $("#pls_select_IPWZone").val();

    validator = $("#gov-land-init-info-form").validate({
        rules:{
            fileNoId:{
                required:true
            },
            districtId:{
                selectBox:"default"
            },
            railwayTrackId:{
                selectBox:"default"
            },
            districtEngineerZoneId:{
                selectBox:"default"
            },
            IPWZoneId:{
                selectBox:"default"
            }/*,
             locationFromMileId:{
             required:true,
             number:true
             },
             locationFromChainId:{
             required:true,
             number:true
             },
             locationToMileId:{
             number:true
             },
             locationToChainId:{
             number:true
             }*/
        },
        messages:{
            fileNoId:{
                required:pls_enter_FileNo
            },
            districtId:{
                selectBox:pls_select_District
            },
            railwayTrackId:{
                selectBox:pls_select_RailwayTrack
            },
            districtEngineerZoneId:{
                selectBox:pls_select_DistrictEngineerZone
            },
            IPWZoneId:{
                selectBox:pls_select_IPWZone
            }/*,
             locationFromMileId:{
             number:pls_enter_valid_no
             },
             locationFromChainId:{
             number:pls_enter_valid_no
             },
             locationToMileId:{
             number:pls_enter_valid_no
             },
             locationToChainId:{
             number:pls_enter_valid_no
             }*/

        },
        invalidHandler: function(form, validator) {
            var errors = validator.numberOfInvalids();
            if (errors) {
                var invalidPanels = $(validator.invalidElements()).closest(".ui-tabs-panel", form);
                if (invalidPanels.size() > 0) {
                    $.each($.unique(invalidPanels.get()), function() {
                        $(this).siblings(".ui-tabs-nav")
                            .find("a[href='#" + this.id + "']").parent().not(".ui-tabs-selected")
                            .addClass("ui-state-error")
                            .show("pulsate", {times: 3});
                    });
                }
            }
        },
        unhighlight: function(element, errorClass, validClass) {
            $(element).removeClass(errorClass);
            $(element.form).find("label[for=" + element.id + "]").removeClass(errorClass);
            var $panel = $(element).closest(".ui-tabs-panel", element.form);
            if ($panel.size() > 0) {
                if ($panel.find("." + errorClass + ":visible").size() == 0) {
                    $panel.siblings(".ui-tabs-nav").find("a[href='#" + $panel[0].id + "']")
                        .parent().removeClass("ui-state-error");
                }
            }
        }
    });
}
